<?php


namespace App\store\controllers\orders;


use App\store\controllers\StoreBaseController;
use App\store\models\OrderModel;
use App\store\services\OrderServices;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class OrderController extends StoreBaseController
{
    protected $class_name = 'Orders';

    /**
     * 获取订单列表
     * $id     int      默认为0
     * $title  string   默认为空
     * @desc 获取订单列表的信息
     */
    public function getOrderList(Request $request) {
        $data = self::getStoreData($this->class_name,'getOrderList', 2);
        if ($data) {
            return $data;
        }
        $data = $request->all();
        $validator = Validator::make(
            $data,
            OrderModel::rules(),
            OrderModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return $this->errorJson($msg[0], []);
        }
        $list = OrderServices::getOrderList($data);
        return successJson('获取成功!', $list);
    }

    /**
     * 获取订单详情
     * $id     int      默认为0
     * @desc 获取订单列表的信息
     */
    public function getOrderDetails(Request $request) {
        $data = self::getStoreData($this->class_name,'getOrderDetails', 2);
        if ($data) {
            return $data;
        }
        $data = $request->all();
        $validator = Validator::make(
            $data,
            OrderModel::detail_rules(),
            OrderModel::message()
        );
        if ($validator->fails()) {
            $msg = $validator->errors()->all();
            return $this->errorJson($msg[0], []);
        }
        $list = OrderServices::getOrderDetail($data);
        return successJson('获取成功!', $list);
    }

}
